package org.acmclass.fatworm.test;

public class Timer {
	private long lastTimePoint, totalTime;
	private boolean running;

	public void start() {
		running = true;
		totalTime = 0;
		lastTimePoint = System.currentTimeMillis();
	}

	public void pause() {
		if (running) {
			totalTime += System.currentTimeMillis() - lastTimePoint;
			running = false;
		}
	}

	public void resume() {
		if (!running) {
			lastTimePoint = System.currentTimeMillis();
			running = true;
		}
	}

	public long getTime() {
		if (running) {
			pause();
			resume();
		}
		return totalTime;
	}
}
